using DevExpress.XtraEditors;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace NoteManger
{
	public class FrmDepCommunicationBook : Form
	{
		private IContainer components = null;
		private ImageList imageList;
		private ContextMenuStrip contextMenuStrip;
		private ToolStripMenuItem pmGroupByRyfl;
		private ToolStripMenuItem pmGroupByJs;
		private ListView listViewPurview;
		private ToolStripSeparator toolStripMenuItem1;
		private ToolStripMenuItem mmCopy;
		private LabelControl lbInfo;
		private NoteRemote _NoteRemoteObject = null;
		private TLoginInfo _LoginInfo = new TLoginInfo();
		public NoteRemote NoteRemoteObject
		{
			set
			{
				this._NoteRemoteObject = value;
			}
		}
		public TLoginInfo LoginInfo
		{
			set
			{
				this._LoginInfo = value;
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(FrmDepCommunicationBook));
			this.imageList = new ImageList(this.components);
			this.contextMenuStrip = new ContextMenuStrip(this.components);
			this.pmGroupByRyfl = new ToolStripMenuItem();
			this.pmGroupByJs = new ToolStripMenuItem();
			this.listViewPurview = new ListView();
			this.lbInfo = new LabelControl();
			this.toolStripMenuItem1 = new ToolStripSeparator();
			this.mmCopy = new ToolStripMenuItem();
			this.contextMenuStrip.SuspendLayout();
			base.SuspendLayout();
			this.imageList.ImageStream = (ImageListStreamer)componentResourceManager.GetObject("imageList.ImageStream");
			this.imageList.TransparentColor = System.Drawing.Color.Transparent;
			this.imageList.Images.SetKeyName(0, "icon20.ico");
			this.contextMenuStrip.Items.AddRange(new ToolStripItem[]
			{
				this.pmGroupByRyfl,
				this.pmGroupByJs,
				this.toolStripMenuItem1,
				this.mmCopy
			});
			this.contextMenuStrip.Name = "contextMenuStrip";
			this.contextMenuStrip.Size = new System.Drawing.Size(159, 76);
			this.pmGroupByRyfl.Name = "pmGroupByRyfl";
			this.pmGroupByRyfl.Size = new System.Drawing.Size(158, 22);
			this.pmGroupByRyfl.Text = "按人员分类分组";
			this.pmGroupByRyfl.Click += new EventHandler(this.pmGroupByRyfl_Click);
			this.pmGroupByJs.Checked = true;
			this.pmGroupByJs.CheckState = CheckState.Checked;
			this.pmGroupByJs.Name = "pmGroupByJs";
			this.pmGroupByJs.Size = new System.Drawing.Size(158, 22);
			this.pmGroupByJs.Text = "按角色分组";
			this.pmGroupByJs.Click += new EventHandler(this.pmGroupByJs_Click);
			this.listViewPurview.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.listViewPurview.ContextMenuStrip = this.contextMenuStrip;
			this.listViewPurview.FullRowSelect = true;
			this.listViewPurview.GridLines = true;
			this.listViewPurview.HideSelection = false;
			this.listViewPurview.Location = new System.Drawing.Point(2, 2);
			this.listViewPurview.Name = "listViewPurview";
			this.listViewPurview.Size = new System.Drawing.Size(719, 405);
			this.listViewPurview.SmallImageList = this.imageList;
			this.listViewPurview.TabIndex = 9;
			this.listViewPurview.TabStop = false;
			this.listViewPurview.UseCompatibleStateImageBehavior = false;
			this.listViewPurview.View = View.Details;
			this.lbInfo.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.lbInfo.Location = new System.Drawing.Point(6, 415);
			this.lbInfo.Name = "lbInfo";
			this.lbInfo.Size = new System.Drawing.Size(214, 14);
			this.lbInfo.TabIndex = 10;
			this.lbInfo.Text = "选择一条记录，然后右键菜单选择“复制”";
			this.toolStripMenuItem1.Name = "toolStripMenuItem1";
			this.toolStripMenuItem1.Size = new System.Drawing.Size(155, 6);
			this.mmCopy.Name = "mmCopy";
			this.mmCopy.ShortcutKeys = (Keys)131139;
			this.mmCopy.Size = new System.Drawing.Size(158, 22);
			this.mmCopy.Text = "复制";
			this.mmCopy.Click += new EventHandler(this.mmCopy_Click);
			base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(722, 436);
			base.Controls.Add(this.lbInfo);
			base.Controls.Add(this.listViewPurview);
			base.Name = "FrmDepCommunicationBook";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "部门通讯录";
			base.WindowState = FormWindowState.Maximized;
			base.Shown += new EventHandler(this.DepCom_Shown);
			this.contextMenuStrip.ResumeLayout(false);
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public FrmDepCommunicationBook()
		{
			this.InitializeComponent();
		}
		private void CreateColumn()
		{
			ColumnHeader columnHeader = new ColumnHeader();
			columnHeader.Text = "用户ID";
			columnHeader.Width = 80;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "用户名称";
			columnHeader.Width = 100;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "部门ID";
			columnHeader.Width = 0;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "部门名称";
			columnHeader.Width = 0;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "组ID";
			columnHeader.Width = 0;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "组名称";
			columnHeader.Width = 100;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "角色ID";
			columnHeader.Width = 0;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "角色名称";
			columnHeader.Width = 120;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "人员分类";
			columnHeader.Width = 100;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "邮件地址";
			columnHeader.Width = 150;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "性别";
			columnHeader.Width = 0;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "手机";
			columnHeader.Width = 80;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "分机";
			columnHeader.Width = 80;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "QQ";
			columnHeader.Width = 100;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
			columnHeader = new ColumnHeader();
			columnHeader.Text = "MSN";
			columnHeader.Width = 150;
			columnHeader.TextAlign = HorizontalAlignment.Left;
			this.listViewPurview.Columns.Add(columnHeader);
		}
		private void mmCopy_Click(object sender, EventArgs e)
		{
			if (this.listViewPurview.SelectedItems.Count != 0)
			{
				string text = this.listViewPurview.SelectedItems[0].SubItems[1].Text;
				text = text + "的联系方式：" + '\n';
				text = text + "    手机号码：" + this.listViewPurview.SelectedItems[0].SubItems[11].Text;
				text += '\n';
				text = text + "    分机号码：" + this.listViewPurview.SelectedItems[0].SubItems[12].Text;
				text += '\n';
				text = text + "    QQ号码：" + this.listViewPurview.SelectedItems[0].SubItems[13].Text;
				text += '\n';
				text = text + "    MSN号码：" + this.listViewPurview.SelectedItems[0].SubItems[14].Text;
				text += '\n';
				Clipboard.SetText(text, TextDataFormat.Text);
				this.lbInfo.Text = "已成功复制<" + this.listViewPurview.SelectedItems[0].SubItems[1].Text + ">的联系方式！";
			}
		}
		private void GetUserListFromRemoteServer()
		{
			this.listViewPurview.Items.Clear();
			if (this._NoteRemoteObject != null)
			{
				try
				{
					if (!this._NoteRemoteObject.ConnectionTest())
					{
						MessageBox.Show("远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message + "远程连接已断开，请重新连接后再试！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					return;
				}
				string[,] array = new string[0, 0];
				string[,] array2 = new string[0, 0];
				string text = "";
				bool flag = false;
				try
				{
					flag = this._NoteRemoteObject.GetUserList("Administrator", "", "", "0", ref array, ref text);
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				if (flag)
				{
					int num = array.GetUpperBound(0) - array.GetLowerBound(0) + 1;
					for (int i = 0; i < num; i++)
					{
						ListViewItem listViewItem = new ListViewItem();
						listViewItem.Text = array[i, 0];
						listViewItem.SubItems.Add(array[i, 1]);
						listViewItem.SubItems.Add(array[i, 2]);
						listViewItem.SubItems.Add(array[i, 3]);
						listViewItem.SubItems.Add(array[i, 4]);
						listViewItem.SubItems.Add(array[i, 5]);
						listViewItem.SubItems.Add(array[i, 6]);
						listViewItem.SubItems.Add(array[i, 7]);
						listViewItem.SubItems.Add(array[i, 8]);
						if (array[i, 6] == "0")
						{
							listViewItem.ForeColor = System.Drawing.Color.Red;
						}
						listViewItem.SubItems.Add(array[i, 9]);
						listViewItem.SubItems.Add(array[i, 10]);
						listViewItem.SubItems.Add(array[i, 11]);
						listViewItem.SubItems.Add(array[i, 12]);
						listViewItem.SubItems.Add(array[i, 13]);
						listViewItem.SubItems.Add(array[i, 14]);
						listViewItem.ImageIndex = 0;
						this.listViewPurview.Items.Add(listViewItem);
					}
					if (this.pmGroupByRyfl.Checked)
					{
						this.pmGroupByRyfl_Click(null, null);
					}
					if (this.pmGroupByJs.Checked)
					{
						this.pmGroupByJs_Click(null, null);
					}
				}
				else
				{
					MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
			}
		}
		private void DepCom_Shown(object sender, EventArgs e)
		{
			this.CreateColumn();
			this.GetUserListFromRemoteServer();
		}
		private void pmGroupByRyfl_Click(object sender, EventArgs e)
		{
			if (this.listViewPurview.Items.Count != 0)
			{
				this.pmGroupByJs.Checked = false;
				this.pmGroupByRyfl.Checked = true;
				this.listViewPurview.Groups.Clear();
				ListViewGroup group = new ListViewGroup("管理人员");
				this.listViewPurview.Groups.Add(group);
				group = new ListViewGroup("普通开发人员");
				this.listViewPurview.Groups.Add(group);
				for (int i = 0; i < this.listViewPurview.Items.Count; i++)
				{
					ListViewItem listViewItem = this.listViewPurview.Items[i];
					if (listViewItem.SubItems[8].Text == "管理人员")
					{
						listViewItem.Group = this.listViewPurview.Groups[0];
					}
					else
					{
						listViewItem.Group = this.listViewPurview.Groups[1];
					}
				}
			}
		}
		private void pmGroupByJs_Click(object sender, EventArgs e)
		{
			if (this.listViewPurview.Items.Count != 0)
			{
				this.pmGroupByJs.Checked = true;
				this.pmGroupByRyfl.Checked = false;
				this.listViewPurview.Groups.Clear();
				ListViewGroup group = new ListViewGroup("部门经理");
				this.listViewPurview.Groups.Add(group);
				group = new ListViewGroup("组管理员");
				this.listViewPurview.Groups.Add(group);
				group = new ListViewGroup("日志特别管理员");
				this.listViewPurview.Groups.Add(group);
				group = new ListViewGroup("一般用户");
				this.listViewPurview.Groups.Add(group);
				group = new ListViewGroup("超级用户");
				this.listViewPurview.Groups.Add(group);
				for (int i = 0; i < this.listViewPurview.Items.Count; i++)
				{
					ListViewItem listViewItem = this.listViewPurview.Items[i];
					if (listViewItem.SubItems[7].Text == "超级用户")
					{
						listViewItem.Group = this.listViewPurview.Groups[4];
					}
					else
					{
						if (listViewItem.SubItems[7].Text == "组管理员")
						{
							listViewItem.Group = this.listViewPurview.Groups[1];
						}
						else
						{
							if (listViewItem.SubItems[7].Text == "一般用户")
							{
								listViewItem.Group = this.listViewPurview.Groups[3];
							}
							else
							{
								if (listViewItem.SubItems[7].Text == "日志特别管理员")
								{
									listViewItem.Group = this.listViewPurview.Groups[2];
								}
								else
								{
									if (listViewItem.SubItems[7].Text == "部门经理")
									{
										listViewItem.Group = this.listViewPurview.Groups[0];
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
